package com.kinggm.controller;

import com.kinggm.model.User;
import com.kinggm.service.UserService;
import com.kinggm.util.PageInfo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    private UserService userService;

    /**
     *
     * 初始化用户数据
     *
     * @return 成功
     */
    @GetMapping("/initData")
    public String initData(){
        userService.insertData();
        return "插入成功";
    }


    @GetMapping("/page")
    public List<User> page(@RequestParam(value = "currentPage") int currentPage,
                           @RequestParam(value = "pageSize") int pageSize,
                           @RequestParam(value = "name",required = false) String name){
        PageInfo pageInfo = new PageInfo(currentPage,pageSize);
        User user = new User();
        user.setName(name);
        List<User> users = userService.searchByPage(pageInfo, user);
        return users;
    }



}
